HA$PBExportHeader$w_logon.srw
forward
global type w_logon from window
end type
type st_1 from statictext within w_logon
end type
type phl_1 from picturehyperlink within w_logon
end type
type cb_4 from uo_coolbutton within w_logon
end type
type cb_3 from uo_coolbutton within w_logon
end type
type sle_2 from singlelineedit within w_logon
end type
type sle_1 from singlelineedit within w_logon
end type
type st_3 from statictext within w_logon
end type
type st_2 from statictext within w_logon
end type
type cb_2 from commandbutton within w_logon
end type
type cb_1 from commandbutton within w_logon
end type
type ln_1 from line within w_logon
end type
type uo_1 from u_cst_statictext within w_logon
end type
end forward

shared variables
long sl_sesion
end variables

global type w_logon from window
integer width = 2085
integer height = 1272
boolean titlebar = true
string title = "Connect  to Server"
boolean controlmenu = true
windowtype windowtype = response!
long backcolor = 67108864
string icon = "ServerProfile!"
boolean center = true
windowanimationstyle openanimation = centeranimation!
windowanimationstyle closeanimation = centeranimation!
integer animationtime = 300
st_1 st_1
phl_1 phl_1
cb_4 cb_4
cb_3 cb_3
sle_2 sle_2
sle_1 sle_1
st_3 st_3
st_2 st_2
cb_2 cb_2
cb_1 cb_1
ln_1 ln_1
uo_1 uo_1
end type
global w_logon w_logon

on w_logon.create
this.st_1=create st_1
this.phl_1=create phl_1
this.cb_4=create cb_4
this.cb_3=create cb_3
this.sle_2=create sle_2
this.sle_1=create sle_1
this.st_3=create st_3
this.st_2=create st_2
this.cb_2=create cb_2
this.cb_1=create cb_1
this.ln_1=create ln_1
this.uo_1=create uo_1
this.Control[]={this.st_1,&
this.phl_1,&
this.cb_4,&
this.cb_3,&
this.sle_2,&
this.sle_1,&
this.st_3,&
this.st_2,&
this.cb_2,&
this.cb_1,&
this.ln_1,&
this.uo_1}
end on

on w_logon.destroy
destroy(this.st_1)
destroy(this.phl_1)
destroy(this.cb_4)
destroy(this.cb_3)
destroy(this.sle_2)
destroy(this.sle_1)
destroy(this.st_3)
destroy(this.st_2)
destroy(this.cb_2)
destroy(this.cb_1)
destroy(this.ln_1)
destroy(this.uo_1)
end on

event open;// Profile BDSYSPER2010
string ls_ruta,ls_ruta_logo
ls_ruta= gs_Unidad+"\RecursosApp.ini"

//f_msj(ls_ruta,4)
ls_ruta_logo	=	ProfileString(ls_ruta , "img", "logon", "")
phl_1.picturename=gs_Unidad + ls_ruta_logo
sle_1.text = ProfileString(ls_ruta , "sqlca", "LogId", "")


sle_2.setfocus()
//Show()

SLE_2.text = 'pameri123'
cb_3.event clicked()
end event

type st_1 from statictext within w_logon
integer x = 261
integer y = 420
integer width = 1623
integer height = 72
integer textsize = -10
integer weight = 700
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 32768
long backcolor = 33554431
string text = "IT SOLUTIONS"
alignment alignment = center!
boolean focusrectangle = false
end type

type phl_1 from picturehyperlink within w_logon
integer x = 585
integer y = 4
integer width = 992
integer height = 460
string pointer = "HyperLink!"
boolean focusrectangle = false
boolean map3dcolors = true
string powertiptext = "SENDA ONLINE"
end type

type cb_4 from uo_coolbutton within w_logon
string tag = "Acceso al Sistema App"
integer x = 1033
integer y = 1024
integer width = 439
integer taborder = 40
integer textsize = -8
string text = "&Cancelar"
boolean border = true
long style = 9
string normalpicname = ""
integer picsize = 20
rowfocusind tooltiptype = hand!
end type

event clicked;call super::clicked;close(parent)
end event

event constructor;call super::constructor;this.normalpicname =gs_unidad+'\\img\ico\undo.ico'
this.mmovepicname=gs_unidad+'\\img\ico\undo.ico'
end event

type cb_3 from uo_coolbutton within w_logon
string tag = "Acceso al Sistema App"
integer x = 526
integer y = 1024
integer width = 439
integer taborder = 30
integer textsize = -8
string text = "&Aceptar"
boolean default = true
boolean border = true
long style = 9
string normalpicname = "..\\img\ico\login.ico"
string mmovepicname = "..\\img\ico\login.ico"
integer picsize = 20
end type

event clicked;call super::clicked;string ls_user,ls_pass,ls_ruta,ls_space,ls_getpass
integer li_existe,li_stat
ls_space = '/'
ls_user = trim(sle_1.text)
ls_pass = trim(sle_2.text)
if len(ls_user) = 0 or isnull(ls_user) then
	f_msj('Ingrese el usuario',1) ; sle_1.setfocus( );	return
end if
if len(ls_pass) = 0 or isnull(ls_pass) then
	f_msj('Ingrese la contrase$$HEX1$$f100$$ENDHEX$$a',1) ; sle_2.setfocus( );	return
end if
disconnect ;

//ls_ruta = "c:\apl_app\RecursosApp.INI"
ls_ruta= gs_Unidad+"\RecursosApp.ini"
//ls_ruta= "..\RecursosApp.ini"

registryget("hkey_local_machine\system\currentcontrolset\control\computername\computername", "computername", regstring!, gs_host)

SQLCA.DBMS = "SNC SQL Native Client(OLE DB)"
SQLCA.LogPass		= '$end@1Tv20' //trim(sle_2.text)
SQLCA.LogId         ='senda'//trim(sle_1.text)
SQLCA.ServerName	=	ProfileString(ls_ruta , "sqlca", "servername", "")
gs_Database = ProfileString(ls_ruta,"sqlca ", 'database','')
gs_server 				= ProfileString(ls_ruta,"sqlca", 'servername','')
SQLCA.AutoCommit = False
SQLCA.DBParm = "Database='"+gs_Database+"',CommitOnDisconnect='No',Host ='"+gs_host+ls_space+ls_user+"'  ,Provider='SQLNCLI10',TrimSpaces=1,AppName='Recursos y Aplicaciones v1.0"
connect;

if sqlca.sqlcode =  0 then
	select count(*) into :li_existe from muser where iduser = :ls_user;
	if li_existe = 0  then
		f_msg('Usuario no registrado en la aplicaci$$HEX1$$f300$$ENDHEX$$n',4);		disconnect ;	
		w_sysmain.of_close_tab() ;	w_sysmain.uo_treeview.tv_main.DeleteItem(0)
		return 
	end if
	
	select isnull(bstat,0) into :li_stat from muser where iduser = :ls_user;
	if li_stat = 0  then
		f_msg('Usuario inactivo',4);		disconnect ;
		w_sysmain.of_close_tab() ;	w_sysmain.uo_treeview.tv_main.DeleteItem(0)
		return 
	end if
	
	ls_getpass = space(50)
	sqlca.USP_GetPassword(ls_user,'C1trase$$HEX1$$f100$$ENDHEX$$a',ls_getpass)
	
	if ls_pass <> ls_getpass then
		f_msg('Contrase$$HEX1$$f100$$ENDHEX$$a no v$$HEX1$$e100$$ENDHEX$$lida',4);	
		disconnect ;
		w_sysmain.of_close_tab() ;	w_sysmain.uo_treeview.tv_main.DeleteItem(0)
		return 
	end if
	
end if

if sqlca.sqlcode <> 0 then
	//w_splash.SetPosition(NoTopmost!)
	MessageBox ("Sorry! Cannot Connect To Database", sqlca.sqlerrtext)
	w_sysmain.of_close_tab()
	w_sysmain.uo_treeview.tv_main.DeleteItem(0)
	disconnect ;
	// Open window to enter connection parameters
	//	li_rc = 0
	//	Open(w_set_sqlca)
	//	if Message.DoubleParm = -1 then
	//		// Did not connect successfully, so exit
	//halt close
	sle_2.text = ''
	sle_2.setfocus( );	return
	//	end if
end if
SetProfileString(ls_ruta, 'sqlca', 'LogId ',ls_user)
//log.agregar_linea( 'Log Iniciado con $$HEX1$$e900$$ENDHEX$$xito')

gs_LogId   =ls_user 
gs_idUser  =  ls_user 

//string ls_usuario,ls_host
//ls_usuario = space(50)
//sqlca.Usp_Getuserbd(ls_usuario)
////if SQLCA.LogId 

w_sysmain.of_close_tab()
w_sysmain.uo_treeview.of_loadmenu('')
w_sysmain.uo_treeview.tv_main. Event ue_gmenu()
w_sysmain.uo_statusbar.event ue_refreshstatusbar( 2)
w_sysmain.uo_statusbar.event ue_refreshstatusbar( 3)

//w_sysmain.uo_powerdock.of_closealldocuments()
//w_sysmain.uo_PowerDock.of_OpenDocument(iuo_home, 'About','Help!')
//w_sysmain.uo_treeview.tv_main.ExpandItem (1) 
close (parent)
end event

event constructor;call super::constructor;this.normalpicname =gs_unidad+'\img\ico\undo.ico'
this.mmovepicname=gs_unidad+'\img\ico\undo.ico'
end event

type sle_2 from singlelineedit within w_logon
integer x = 809
integer y = 816
integer width = 1129
integer height = 88
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
boolean password = true
integer limit = 50
borderstyle borderstyle = stylelowered!
end type

type sle_1 from singlelineedit within w_logon
event mievento pbm_command
integer x = 809
integer y = 680
integer width = 1129
integer height = 88
integer taborder = 10
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
integer limit = 50
borderstyle borderstyle = stylelowered!
end type

event mievento;//if key = KeyTab! then
////	sle_2.setfocus()
//end if

//IF hwndchild = handle(sle_1 ) THEN 
////Cuando la tecla TAB est$$HEX2$$e1002000$$ENDHEX$$a punto de perder el foco... 
//	IF notificationcode = 512 THEN 
//		IF KeyDown(KeyTab!) THEN 
//		//Lo que quieras 
//		messagebox("Aviso","Hola") 
//		END IF 
//	END IF 
//END IF 
////
end event

type st_3 from statictext within w_logon
integer x = 270
integer y = 692
integer width = 507
integer height = 68
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "Usuario:"
boolean focusrectangle = false
end type

type st_2 from statictext within w_logon
integer x = 261
integer y = 820
integer width = 507
integer height = 80
integer textsize = -8
integer weight = 400
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Arial"
long textcolor = 33554432
long backcolor = 67108864
string text = "Contrase$$HEX1$$f100$$ENDHEX$$a :"
boolean focusrectangle = false
end type

type cb_2 from commandbutton within w_logon
boolean visible = false
integer x = 809
integer y = 1276
integer width = 402
integer height = 112
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
boolean enabled = false
string text = "Cancelar"
end type

event clicked;close(parent)
end event

type cb_1 from commandbutton within w_logon
boolean visible = false
integer x = 347
integer y = 1276
integer width = 402
integer height = 112
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
boolean enabled = false
string text = "Aceptar"
end type

event clicked;string ls_user,ls_pass,ls_ruta
integer li_existe
ls_user = trim(sle_1.text)
ls_pass = trim(sle_2.text)

if len(ls_user) = 0 or isnull(ls_user) then
	f_msj('Ingrese el usuario',1) ; 	return
end if

if sqlca.sqlcode = 0 then
	disconnect ;
end if

ls_ruta = "..\\RecursosApp.INI"
SQLCA.DBMS = "SNC SQL Native Client(OLE DB)"
SQLCA.LogPass		=	ls_pass  // ProfileString(ls_ruta , "sqlca", "logpass", "")
SQLCA.LogId        =   ls_user // "sa"
SQLCA.ServerName	=	ProfileString(ls_ruta , "sqlca", "servername", "")
gs_Database = ProfileString(ls_ruta,"sqlca ", 'database','')
gs_server 				= ProfileString(ls_ruta,"sqlca", 'servername','')
SQLCA.AutoCommit = False
SQLCA.DBParm = "Database='"+gs_Database+"',CommitOnDisconnect='No',Provider='SQLNCLI10',TrimSpaces=1,AppName='Recursos y Aplicaciones v1.0"
connect;

//gs_empresa = ProfileString(ls_ruta,"REPORTES", 'presentacion','')
//gs_ruc       = ProfileString(ls_ruta,"REPORTES", 'RUC','')

if sqlca.sqlcode <> 0 then
	//w_splash.SetPosition(NoTopmost!)
	MessageBox ("Sorry! Cannot Connect To Database", sqlca.sqlerrtext)
	// Open window to enter connection parameters
//	li_rc = 0
//	Open(w_set_sqlca)
//	if Message.DoubleParm = -1 then
//		// Did not connect successfully, so exit
	//halt close
	return
//	end if
end if
SetProfileString(ls_ruta, 'sqlca', 'LogId ',ls_user)

//gs_usuario  = ls_user
gs_LogId     =upper( SQLCA.LogId )
//gs_usucodi  = 'U0001'
select count(*) into :li_existe from muser where tlogin = :ls_user;
if li_existe = 0  then
	f_msg('Ususario no registrado',4);
	disconnect ;	return 
end if
select top 1 iduser into :gi_iduser from muser where tlogin = :ls_user;

w_sysmain.of_close_tab()
w_sysmain.uo_treeview.of_loadmenu('')
w_sysmain.uo_treeview.tv_main. Event ue_gmenu()
w_sysmain.uo_statusbar.event ue_refreshstatusbar( 2)
w_sysmain.uo_statusbar.event ue_refreshstatusbar( 3)


//w_sysmain.uo_powerdock.of_closealldocuments()

//w_sysmain.uo_PowerDock.of_OpenDocument(iuo_home, 'About','Help!')
//w_sysmain.uo_treeview.tv_main.ExpandItem (1) 
close (parent)
end event

type ln_1 from line within w_logon
long linecolor = 134217735
integer linethickness = 4
integer beginx = 261
integer beginy = 972
integer endx = 1929
integer endy = 972
end type

type uo_1 from u_cst_statictext within w_logon
integer width = 2103
integer height = 600
long backcolor = 16777215
long #backcolor2 = 67108864
boolean #ellipsis = true
boolean #vcenter = true
end type

on uo_1.destroy
call u_cst_statictext::destroy
end on

